from django.db import models
from django.contrib.auth import get_user_model

OAUser = get_user_model()


class AbsentStatusChoices(models.IntegerChoices):
    AUDITING = 1  # 审批中
    PASS = 2  # 通过
    REJECT = 3  # 拒绝


# Create your models here.
class AbsentType(models.Model):
    name = models.CharField(max_length=100)
    create_time = models.DateTimeField(auto_now_add=True)


class Absent(models.Model):
    title = models.CharField(max_length=200)  # 标题
    request_content = models.TextField()  # 请假内容
    absent_type = models.ForeignKey(AbsentType, on_delete=models.CASCADE,
                                    related_name='absent', related_query_name='absent')
    requester = models.ForeignKey(OAUser, on_delete=models.CASCADE,
                                  related_name='my_absent', related_query_name='my_absent')
    responder = models.ForeignKey(OAUser, on_delete=models.CASCADE,
                                  related_name='sub_absent', related_query_name='sub_absent', null=True)
    status = models.IntegerField(choices=AbsentStatusChoices, default=AbsentStatusChoices.AUDITING)
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()
    create_time = models.DateTimeField(auto_now_add=True)
    response_content = models.TextField(blank=True, null=True)

    class Meta:
        ordering = ['-create_time']